package com.maigao.persistent;

import com.maigao.entity.jpa.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface StudentRepository extends JpaRepository<Student, Long> {
    Student findById(Integer id);

    Student findByUserUidAndStudentName(String userUid, String studentName);

    List<Student> findByCoachId(Integer coachId);

    List<Student> findByCreateTimeBetween(LocalDateTime fromTime, LocalDateTime endTime);

    List<Student> findByCoachIdAndStatus(Integer coachId, Integer status);

    List<Student> findByUserUid(String userUid);

    @Modifying
    @Query("update Student set status = ?2 where id = ?1")
    void updateStudentStatus(Integer studentId, int newStatus);

    @Query("select u from Student u where u.studentName like %?1% and u.status = ?2")
    List<Student> findByStudentNameLikeAndStatus(String studentName, Integer status);
}
